     /*
 *@本js功能：制作章节添加
 *@本js作者：杨锡君
 *@编写时间：2018年06月28日
 */
     var testEditor;
$(function() {
    var count = 0;
    var num = 0;
    var loading1 = new Loading();
    loading1.init();
    var Alert2 = new Alert();
    function choseModel(num,opt){

//		选择题模板
       var str1 = "";
        // count = num-1;
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +" class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(&emsp;&emsp;)(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<i style='font-style: normal;' class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</i></div>"
            $.each(this.tasklibraryOptionMsg.split("#"), function(omg) {
                str1 += "<div class=\"choseOne\">"+ this +"</div>"
            });
            str1 +="</div>";
        });

        return str1;
    }
    function muchModel(num,opt,obj){
      var str1 = "";
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +" class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(&emsp;&emsp;)(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<i style='font-style: normal;' class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</i></div>"
            $.each(this.tasklibraryOptionMsg.split("#"), function(omg) {
                str1 += "<div class=\"muchOne\">"+ this +"</div>"
            });
            str1 +="</div>";
        });

        return   str1;
    }
    function fillModel(num,opt,obj){

//		填空题模板
       var str1 = "";
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +"  class=\"questionBox\">"
                +"<div class=\"fillAdd\"><i style='font-style: normal;' class=\"fillSpace\">"+ num +"."+ this.tasklibraryName +"</i>(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<div class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</div></div>"
                +"</div>";
        });

        return  str1;
    }
    function checkModel(num,opt,obj){

     var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +"   class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(&emsp;&emsp;)(<i class=\"fen\">"+ this.tasklibrarySource +"</i>分)<i style='font-style: normal;' class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</i></div>"
                +"</div>";
        });
        return str1;

    }
    function shortModel(num,opt,obj){

        var str1 = "";
        $.each(opt, function(key) {
            num++;
            str1 += "<div data-questionid="+ this.tasklibraryId +" data-questiontype="+ this.tasklibraryType +" class=\"questionBox\">"
                +"<div>"+ num +"."+ this.tasklibraryName +"(<i style='font-style: normal;' class=\"fen\">"+ this.tasklibrarySource +"</i>分)<div class=\"trueAnswer\">正确答案："+ this.tasklibraryAnswer +"</div></div>"
                +"<div class=\"choseOne\"><textarea maxlength='2000' class=\"shortAnswer answerInt\"></textarea></div>"
                +"</div>";
        });
        return  str1;

    }
    function labModel(opt) {
        return "<b>一、"+ opt.exprelibraryName +"</b><div><br></div><div><b><br></b></div><div><b>二、"+ opt.exprelibraryObjective +"</b></div><div><br></div><div><b><br></b></div><div><b>三、"+ opt.exprelibraryContent +"</b></div><div><br></div><div><b><br></b></div><div><b>四、"+ opt.exprelibraryStep +"</b></div><div><br></div><div><b><br></b></div><div><b>五、"+ opt.exprelibraryResult +"</b></div><div><br></div><div><b><br></b></div><div><b>六、"+ opt.exprelibraryThinkproblem +"</b></div><div><br></div><div><b><br></b></div>";
    }
    function saveImage() {
        return '<div class="saveImgBg"></div><div class="popup saveImageBox" style="display: block;top: 30%;">' +
            '<div class="popup_box">' +
            '<div class="popup_contenthead">保存镜像<img class="popup_img imageClose" src="pc/images/ico_alertDel.png"></div>' +
            '<div class="popup_content" style="min-height: 128px">' +
            '<div class="hideBox"><label>覆盖原有镜像:&ensp;</label>' +
            '<span class="form-control form-controls" style="box-shadow: none;">' +
            '<span  data-value="1" class="type radioc radioCheck2">是</span>' +
            '<span  data-value="2" class="type radioc">否</span>' +
            '</span>' +
            '<div class="clear"></div>' +
            '</div>'+
            '<div style="margin-left: 52px;margin-top: 34px;display: none;" class="inputRight inBox fl"><label for="imgName">镜像名称:&ensp;</label>' +
            '<input type="text" class="publicText" id="imgName">' +
            '</div>' +
            '</div>' +
            '<div class="popup_btn">' +
            '<a  class="popup_confirm exportBtn saveImgTrue publicBtn hover-btn">确定</a>' +
            '<a class="popup_close exportCancle imageClose ">取消</a>' +
            '</div>' +
            '<div class="clear"></div>' +
            '</div>' +
            '</div>';
    }
    function testDocModel() {
        return '<div id="layoutSub">' +
            '<header id="labTitle">' +
            '<h4 class="fl saveLabs">保存</h4>' +
            '<img class="closeLab" src="pc/images/ico_alertDel.png">' +
            '</header>' +
            '<div id="LabEditormds">' +
            '<textarea style="display:none;"></textarea>' +
            '</div>' +
            '</div>';
    }
    function shearModel() {
        return '<div class="modal" id="clipboard-modal" tabindex="-1" role="dialog" style="display: block;">' +
            '<div class="modal-dialog" role="document">' +
            '<div class="modal-content">' +
            '<div class="modal-header">' +
            '<img class="alert_img shearClose" src="pc/images/ico_alertDel.png"></span>' +
            '<h4 class="modal-title">剪切板</h4>' +
            '</div>' +
            '<div class="modal-body">' +
            '<div>' +
            '<strong>复制外部内容到实验环境内：</strong>粘贴内容到下方输入框，点击‘保存’在实验环境中粘贴。' +
            '</div>' +
            '<textarea maxlength="20000" class="maxLimit" id="praseArea"></textarea>' +
            '</div>' +
            '<div class="modal-footer">' +
            '<button class="  clipboard-copy-btn publicBtn" type="button">保存</button>' +
            '<button class="  shearClose publicBtn" type="button" data-dismiss="modal">关闭</button>' +
            '</div>' +
            '</div>' +
            '</div>' +
            '</div>';
    }
    var Alert1 = new Alert();
    var confirm1 = new Confirm();
    var loading1 = new Loading();
    loading1.init();
    var chapterAdd = {
        init:function () {
            this.bindEvent();
        },
        bindEvent:function () {
            var self = this;
            self.getDataEvent();
            $(".looktg").off("click").click(function () {
                var json = JSON.stringify({
                    "pageName": $(this).attr("data-url"),
                    "paramData": {
                        "some": result.paramData.some
                    }
                });
                window.location.href = "skipPage?jsonStr=" + json;
            });
        },
        getImage:function (mark) {
            var self = this;
            var flag = true;
            if(mark != undefined){
                flag = mark;
            }
            $.ajax({
                type: "get",
                url: "image/list",
                data:{"isInitial":flag},
                async: true,
                success: function(msg) {
                    if(msg.code == 200) {
                        $("#oneImage").empty();
                        if(msg.data.length != 0) {
                            //列表
                            var tabel = "";
                            $.map(msg.data, function(opt) {
                                tabel += "<option value='"+ opt.id +"'>"+ opt.name +"</option>";
                            });
                            $("#oneImage").append(tabel);
                        }
                    } else {
                        Alert1.content = msg.message;
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }

                }
            });
        },
        getAllImage:function () {
            var self = this;
            $.ajax({
                type: "get",
                url: "cluster/listByAllocate",
                async: true,
                success: function(msg) {
                    if(msg.code == 200) {
                        $("#images").empty();
                        if(msg.data.length != 0) {
                            //列表
                            var tabel = "";
                            $.map(msg.data, function(opt) {
                                tabel += "<option value='"+ opt.id +"'>"+ opt.name +"</option>";
                            });
                            $("#images").append(tabel);
                        }
                    } else {
                        Alert1.content = msg.message;
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }

                }
            });
        },
        allocateEvent:function () {
            var self = this;
            $(".popup,.mb").show();
            $(".come,.imageBox").show();

            self.getImage();
            $(".imagesBox").hide();
            $(".type").removeClass("radioCheck");
            $(".type").eq(0).addClass("radioCheck");
            $(".types").removeClass("radioChecks");
            $(".types").eq(0).addClass("radioChecks");
            $(".type").off("click").click(function () {
                $(this).addClass("radioCheck");
                $(this).siblings("span").removeClass("radioCheck");
                if($(this).attr("data-value") == 1){
                    $(".come,.imageBox").show();
                    $(".imagesBox").hide();
                    $(".types").removeClass("radioChecks");
                    $(".types").eq(0).addClass("radioChecks");
                    $("#oneConfig").val('2,2');
                    self.getImage(true);
                }else{
                    $(".come,.imageBox").hide();
                    $(".imagesBox").show();
                    $("#imagesFir").val('2,2');
                    $("#imagesSec").val('2,2');
                    $("#imagesThi").val('2,2');
                    self.getAllImage();
                }
            });
            $(".types").off("click").click(function () {
                $(this).addClass("radioChecks");
                $(this).siblings("span").removeClass("radioChecks");
                if($(this).attr("data-value") == 1){
                    self.getImage(true);
                }else{
                    self.getImage(false);
                }
            });
            // 取消 x
            $(".exportCancle").off("click").click(function () {
                $(".popup,.mb").hide();
            });
            $(".popup_img").off("click").click(function () {
                $(".popup,.mb").hide();
            });
            var clusterId;
            var imageId;
            // 提交
            $(".exportBtn").off("click").click(function () {

                var flag = true;
                var json = {};
                var url = '';
                var type = 0;
                var flavor = '';
                if ($(".radioCheck").attr("data-value") == 1) {
                    // json.cluster = false;
                    json.imageId = Number($("#oneImage").val());
                    imageId = Number($("#oneImage").val());
                    flavor = $("#oneConfig").val();
                    url = "image/desktop";
                    type = 1;
                    if ($("#oneImage").val() == null) {
                        Alert1.content = "请正确选择镜像";
                        Alert1.init();
                        Alert1.show();
                        flag = false;
                        return false;
                    }
                } else {
                    // json.cluster = true;
                    json.clusterId = Number($("#images").val());
                    clusterId = Number($("#images").val());
                    type = 2;
                    flavor = $("#imagesFir").val() + "," + $("#imagesSec").val() + "," + $("#imagesThi").val();
                    url = "cluster/desktop";
                    if ($("#images").val() == null) {
                        Alert1.content = "请正确选择集群";
                        Alert1.init();
                        Alert1.show();
                        flag = false;
                        return false;
                    }
                }
                if (flag) {
                    loading1.show();
                    $.ajax({
                        type: "get",
                        url: url,
                        data: json,
                        async: true,
                        success: function (msg) {
                            loading1.hide();
                            if (msg.code == 200) {
                                $(".virEnvirmentBox").remove();
                                $("#layoutSub").remove();
                                $("#virtualBox").remove();
                                $(".sftpBox").remove();
                                $(".navSideBar").remove();
                                $(".modal").remove();
                                $(".packDown").remove();
                                $("#ifMain", parent.document).css({
                                    "position": "fixed",
                                    "left": 0,
                                    "top": 0,
                                    "z-index": 100
                                });
                                $("body").css("overflow", "hidden");
                                $(".virEnvirmentBox").remove();
                                $("body").append('<div class="virEnvirmentBox" style="width: 100%;">' +
                                    '<div class="titleBox">' +
                                    '<div title="关闭" class="fr cancelBtn "><img src="pc/images/ico_shareClose.png" alt="关闭"></div>' +
                                    '<div class="configBox">' +
                                    '<ul>' +
                                    '</ul>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="navSideBar">' +
                                    '<div data-value="0" class="closeSide">' +
                                    '工具栏' +
                                    '</div>' +
                                    '<div class="toolsBox">' +
                                    '<ul>' +
                                    '<li class="relink">刷新</li>' +
                                    '<li class="exchangeBtn">重选配置</li>' +
                                    '<li class="saveImg">保存镜像</li>' +
                                    '<li class="line"></li>' +
                                    '<li class="sftp">SFTP工具</li>' +
                                    '<li class="shearBoardBtn">剪切板</li>' +
                                    '<li class="line virAfter"></li>' +
                                    '</ul>' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="sftpBox">' +
                                    '<div class="sftpContentBox">' +
                                    '<header>' +
                                    'SFTP工具' +
                                    '<img class="closeSftp" src="pc/images/ico_alertDel.png">' +
                                    '</header>' +
                                    '<div class="sftpContent">' +
                                    '<div>' +
                                    '<div>您可以使用SFTP工具上传、下载文件：</div>' +
                                    '<div>SFTP访问的地址为 <i class="blue blueHtml"></i> 端口号为 <i class="blue blueHtml2"></i></div>' +
                                    '<div>用户名： <i class="blue">root</i>&ensp;   密码： <i class="blue">root</i> </div>' +
                                    '<hr>' +
                                    '<h4>使用说明</h4>' +
                                    '<div class="marg">1.请先下载SFTP工具&emsp;<a href="upload/pscp/psftp_64.exe" download> <img class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down64.png"> </a>&emsp;&emsp;&emsp;<a href="upload/pscp/psftp_32.exe.exe" download> <img  class="downImg" src="pc/images/ico_sftpDown.png" alt=""><img class="bit" src="pc/images/ico_down32.png"> </a></div>' +
                                    '<div class="marg">2.使用登陆命令   <i class="grayBg">open username@host post</i></div>' +
                                    '<div class="marg">说明：username为用户名 host 为主机地址，post为端口号。</div>' +
                                    '<div class="marg">3.填写密码进入SFTP环境。</div>' +
                                    '<div class="marg">4.上传命令   <i class="grayBg">put dir/something.txt  dir/another.txt  </i></div>' +
                                    '<div class="marg">说明：dir/something.txt 为用户当前环境的地址+文件。dir/another.txt为虚拟环境的地址加文件。</div>' +
                                    '<div class="marg">例如：命令 put D:/bigdata.sql  /home/bigdata.sql  则是把本地D盘的bigdata.sql 文件上传至虚拟环境home 目录。</div>' +
                                    '<div class="marg">5.下载命令   <i class="grayBg">get  dir/something.txt   dir/another.txt </i></div>' +
                                    '<div class="marg">说明：dir/something.txt 为虚拟环境的地址加文件。dir/another.txt用户当前环境的地址+文件。</div>' +
                                    '<div class="marg">例如：命令 get /home/bigdata.sql  E:/bigdata.sql  则是把虚拟环境home 目录的bigdata.sql 文件下载至的本地E盘。</div>' +
                                    '<div class="publicBtn fr closeSftp ">确定</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '<div id="virtualBox">' +
                                    '</div>' +
                                    '</div>');
                                $("#virtualBox").height($(window).height() - 40);
                                $(".contentSection").height($(window).height() - 40);
                                $(".navSideBar").height($(window).height() - 40);
                                $(window).resize(function () {
                                    $("#virtualBox").height($(window).height() - 40);
                                    $(".contentSection").height($(window).height() - 40);
                                    $(".navSideBar").height($(window).height() - 40);
                                });
                                //编辑器
                                $("body").append(testDocModel());
                                var testEditors = editormd('LabEditormds', {
                                    width: '100%',
                                    height: 480,
                                    toc: true,
                                    todoList: true,
                                    path: 'pc/js/extends/lib/',
                                    watch: false,
                                    saveHTMLToTextarea: true,
                                    imageUpload: true,
                                    imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                    imageUploadURL: "editormdPic/",
                                    tex:true,
                                    flowChart: true,
                                    sequenceDiagram: true,
                                    dialogLockScreen: false,
                                    dialogShowMask: true,
                                    dialogDraggable: false,
                                    dialogMaskOpacity: 0.4,
                                    dialogMaskBgColor: "#000",
                                    toolbarIcons: function () {
                                        return ["undo", "redo", "|", "bold", "italic", "quote", "uppercase", "lowercase", "|", "h1", "h2", "h3", "h4", "|", "list-ul", "list-ol", "hr", "|", "link", "image", "code", "preformatted-text", "code-block", "table", "|", "watch", "preview", "fullscreen", "clear"]
                                    }
                                });
                                $("#LabEditormds textarea").val($("#LabEditormd textarea").val());
                                $(".closeLab").off("click").click(function () {
                                    $("#layoutSub").hide();
                                    $("body").append("<img src=\"pc/images/ico_labEditBtn.png\" class=\"packDown\" >");
                                    $(".packDown").off("click").click(function () {
                                        $("#layoutSub").show();
                                        var val =  $("#LabEditormds textarea").val();
                                        testEditors = editormd('LabEditormds', {
                                            width     : '100%',
                                            height    : 480,
                                            toc       : true,
                                            todoList  : true,
                                            path      : 'pc/js/extends/lib/',
                                            watch:false,
                                            saveHTMLToTextarea : true,
                                            imageUpload : true,
                                            tex:true,
                                            imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                                            imageUploadURL : "editormdPic/",
                                            flowChart: true,
                                            sequenceDiagram: true,
                                            dialogLockScreen : false,
                                            dialogShowMask : true,
                                            dialogDraggable : false,
                                            dialogMaskOpacity : 0.4,
                                            dialogMaskBgColor : "#000",
                                            toolbarIcons : function() {
                                                return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                                            }
                                        });
                                        $("#LabEditormds textarea").val(val);
                                        $(this).remove();
                                    });
                                });
                                var div1 = document.getElementById("layoutSub");
                                var div2 = document.getElementById("labTitle");
                                div2.onmousedown = function (e) {
                                    var e = e || window.event;
                                    var x = e.clientX - div1.offsetLeft;
                                    var y = e.clientY - div1.offsetTop;
                                    if (e.preventDefault) {
                                        e.preventDefault();
                                    }
                                    else {
                                        e.returnValue = false;
                                    }
                                    document.onmousemove = function (e) {
                                        var e = e || window.event;
                                        if (e.preventDefault) {
                                            e.preventDefault();
                                        }
                                        else {
                                            e.returnValue = false;
                                        }
                                        var wid = e.clientX - x;
                                        var hei = e.clientY - y;
                                        div1.style.left = wid + "px";
                                        div1.style.top = hei + "px";
                                    }
                                };
                                document.onmouseup = function (e) {
                                    var e = e || event;
                                    document.onmousemove = null;
                                    if (e.preventDefault) {
                                        e.preventDefault();
                                    }
                                    else {
                                        e.returnValue = false;
                                    }
                                };
                                // 剪切板
                                $(".shearBoardBtn").off("click").click(function () {
                                    var string = shearModel();
                                    $("#clipboard-modal").remove();
                                    $("body").append(string);
                                    maxLengthLimit.init("maxLimit");
                                    $(".shearClose").off("click").click(function () {
                                        $(".modal").remove();
                                    });
                                    $(".clipboard-copy-btn").off("click").click(function () {
                                        loading1.show();
                                        var jsonStr = JSON.stringify({
                                            "content": $("#praseArea").val(),
                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                        });
                                        $.ajax({
                                            type: "post",
                                            url: "desktop/clipboard",
                                            data: jsonStr,
                                            async: true,
                                            dataType: 'json',
                                            contentType: 'application/json',
                                            success: function (msg) {
                                                loading1.hide();
                                                if (msg.code == "200") {
                                                    $(".modal").remove();
                                                    Alert1.content = "保存成功，请在实验环境中粘贴内容";
                                                    Alert1.init();
                                                    Alert1.show();
                                                } else {
                                                    Alert1.content = msg.message;
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });
                                    });
                                });

                                // SFTP
                                $(".sftp").off("click").click(function () {
                                    $(".sftpBox").show();
                                    // 获取sftp地址和端口
                                    $.ajax({
                                        type: "get",
                                        url: "desktop/ftp",
                                        data: {"containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                        async: true,
                                        dataType: 'json',
                                        contentType: 'application/json',
                                        success: function (msg) {
                                            if (msg.code == "200") {
                                                var arr = msg.data.ftp.split(":");
                                                $(".blueHtml").html(arr[0]);
                                                $(".blueHtml2").html(arr[1]);
                                            } else {
                                                Alert1.content = msg.message;
                                                Alert1.init();
                                                Alert1.show();
                                                return false;
                                            }
                                        }
                                    });
                                });
                                $(".closeSftp").off("click").click(function () {
                                    $(".sftpBox").hide();
                                });
                                //刷新
                                $(".relink").off("click").click(function () {
                                    var url = $(".virMBox[data-value=1]").attr("src");
                                    $(".virMBox[data-value=1]").attr("src", url);
                                });
                                // 工具栏
                                $(".closeSide").off("click").click(function () {
                                    if ($(this).attr("data-value") == 0) {
                                        $(this).attr("data-value", 1);
                                        $(".navSideBar").animate({
                                            "right": "-120px"
                                        }, 300);
                                    } else {
                                        $(this).attr("data-value", 0);
                                        $(".navSideBar").animate({
                                            "right": "0"
                                        }, 300);
                                    }
                                });
                                // 实验手册保存
                                $(".saveLabs").off("click").click(function () {
                                    var json = JSON.stringify({
                                        "chapterId": result.paramData.chapterId,
                                        "testNameHtml": escape($("#LabEditormds textarea").val()),
                                        "courseMaterialNameHtml": '',
                                        "mark": 2,
                                        "htmlStr":$("#LabEditormds .editormd-preview").html()
                                    });
                                    if($("#LabEditormds textarea").val()!=''&& $("#LabEditormds .markdown-body").html() == ''){
                                        Alert1.content = "请点击预览查看编写效果";
                                        Alert1.init();
                                        Alert1.show();
                                    }else{
                                        $.ajax({
                                            type: 'post',
                                            url: 'addChapterMaterialOrTest',
                                            async: true,
                                            data: {
                                                "jsonStr": json
                                            },
                                            success: function (msg) {
                                                msg = JSON.parse(msg);
                                                if (msg.result == "success") {
                                                    Alert1.content = "保存成功";
                                                    Alert1.init();
                                                    Alert1.show();
                                                } else {
                                                    if (msg.failMsg != undefined) {
                                                        Alert1.content = msg.failMsg;
                                                    } else {
                                                        Alert1.content = "添加章节失败";
                                                    }
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });
                                    }

                                });
                                // 返回上一页
                                $(".cancelBtn").off("click").click(function () {
                                    confirm1.content = "确定退出实验环境吗？";
                                    confirm1.success = function () {
                                        $("#ifMain", parent.document).attr("style", "");
                                        $(".virEnvirmentBox").remove();
                                        self.testEditor("LabEditormd");
                                        $("#LabEditormd textarea").val($("#LabEditormds textarea").val());
                                        $("#LabEditormd .markdown-body").html('');
                                        $("#layoutSub").remove();
                                        $("#virtualBox").remove();
                                        $(".sftpBox").remove();
                                        $(".navSideBar").remove();
                                        $(".modal").remove();
                                        $(".packDown").remove();
                                        $("body").css("overflow", "inherit");
                                    };
                                    confirm1.init();
                                    confirm1.show();
                                });
                                $(".popup,.mb").hide();
                                $(".come,.imageBox").show();
                                $(".imagesBox").hide();
                                $(".types").removeClass("radioChecks");
                                $(".types").eq(0).addClass("radioChecks");
                                $("#oneConfig").val('2,2');
                                self.getImage(true);
                                // 配置
                                var str = '';
                                var str1 = '';
                                if (msg.data.masterImageId != undefined) {
                                    str += "<li data-value='1' data-url='" + msg.data.masterDesktopUrl + "'  data-containerid=" + msg.data.masterContainerId + ">主节点(当前)</li>";
                                    str += "<li data-value='0' data-url='" + msg.data.firstSlaveDesktopUrl + "'  data-containerid=" + msg.data.firstSlaveContainerId + ">从节点1</li>";
                                    str += "<li data-value='0' data-url='" + msg.data.secondSlaveDesktopUrl + "'  data-containerid=" + msg.data.secondSlaveContainerId + ">从节点2</li>";
                                    $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='" + msg.data.masterImageId + "' data-value='1' data-containerid=" + msg.data.masterContainerId + " class=\"virMBox\" src=" + msg.data.masterDesktopUrl + "  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                    $("#virtualBox").append("<iframe name='virMBoxes' data-imageid='" + msg.data.firstSlaveImageId + "'  data-value='0' data-containerid=" + msg.data.firstSlaveContainerId + " class=\"virMBox\" src=" + msg.data.firstSlaveDesktopUrl + "  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                    $("#virtualBox").append("<iframe name='virMBoxes'  data-imageid='" + msg.data.secondSlaveImageId + "' data-value='0' data-containerid=" + msg.data.secondSlaveContainerId + " class=\"virMBox\" src=" + msg.data.secondSlaveDesktopUrl + "  frameborder=\"0\" style=\"width: 100%;height: 100%;display: none;\"></iframe>");
                                    // $(".configBox>ul").html(str);
                                    str1 += "<li type='1' class='nav mainVir' data-value='1' data-url='" + msg.data.masterDesktopUrl + "'  data-containerid=" + msg.data.masterContainerId + ">主节点</li>";
                                    str1 += "<li type='2' class='nav subVir' data-value='0' data-url='" + msg.data.firstSlaveDesktopUrl + "'  data-containerid=" + msg.data.firstSlaveContainerId + ">从节点1</li>";
                                    str1 += "<li type='2' class='nav thVir' data-value='0' data-url='" + msg.data.secondSlaveDesktopUrl + "'  data-containerid=" + msg.data.secondSlaveContainerId + ">从节点2</li>";
                                    $(".virAfter").after(str1);
                                    startWebSocket(msg.data.masterContainerId);
                                    startWebSocket(msg.data.firstSlaveContainerId);
                                    startWebSocket(msg.data.secondSlaveContainerId);
                                    $(".saveImg").html("保存集群");
                                } else {
                                    $(".saveImg").html("保存镜像");
                                    // str += "<li data-value='1' data-url='"+ msg.data.desktopUrl +"'  data-containerid="+ msg.data.containerId +">单节点(当前)</li>";
                                    $("#virtualBox").append("<iframe   name='virMBoxes' data-imageid='" + msg.data.imageId + "' data-value='1' data-containerid=" + msg.data.containerId + " class=\"virMBox\" src=" + msg.data.desktopUrl + "  frameborder=\"0\" style=\"width: 100%;height: 100%;\"></iframe>");
                                    startWebSocket(msg.data.containerId);
                                }
                                $(".mainVir").css({
                                    "background": 'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',
                                    "color": '#0fcc8c'
                                });
                                $(".mainVir").off("click").click(function () {
                                    $(".nav").attr("style", '');
                                    $(".nav").attr("data-value", '0');
                                    $(this).css({
                                        "background": 'url(pc/images/ico_labMPC2.png) no-repeat left 6px center',
                                        "color": '#0fcc8c'
                                    });
                                    $(this).attr("data-value", "1");
                                    $(".virMBox").attr("data-value", "0").hide();
                                    $(".virMBox[data-containerid=" + $(this).attr("data-containerid") + "]").attr("data-value", "1").show()
                                });
                                $(".subVir").off("click").click(function () {
                                    $(".nav").attr("style", '');
                                    $(".nav").attr("data-value", '0');
                                    $(this).css({
                                        "background": 'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',
                                        "color": '#0fcc8c'
                                    });
                                    $(this).attr("data-value", "1");
                                    $(".virMBox").attr("data-value", "0").hide();
                                    $(".virMBox[data-containerid=" + $(this).attr("data-containerid") + "]").attr("data-value", "1").show()
                                });
                                $(".thVir").off("click").click(function () {
                                    $(".nav").attr("style", '');
                                    $(".nav").attr("data-value", '0');
                                    $(this).css({
                                        "background": 'url(pc/images/ico_labSPC2.png) no-repeat left 6px center',
                                        "color": '#0fcc8c'
                                    });
                                    $(this).attr("data-value", "1");
                                    $(".virMBox").attr("data-value", "0").hide();
                                    $(".virMBox[data-containerid=" + $(this).attr("data-containerid") + "]").attr("data-value", "1").show()
                                });

                                // 获取sftp地址和端口
                                $.ajax({
                                    type: "get",
                                    url: "desktop/ftp",
                                    data: {"containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))},
                                    async: true,
                                    dataType: 'json',
                                    contentType: 'application/json',
                                    success: function (msg) {
                                        if (msg.code == "200") {
                                            var arr = msg.data.ftp.split(":");
                                            $(".blueHtml").html(arr[0]);
                                            $(".blueHtml2").html(arr[1]);
                                        } else {
                                            Alert1.content = msg.message;
                                            Alert1.init();
                                            Alert1.show();
                                            return false;
                                        }
                                    }
                                });
                                //重新选择镜像
                                $(".exchangeBtn").off("click").click(function () {
                                    self.testEditor("LabEditormd");
                                    $("#LabEditormd textarea").val($("#LabEditormds textarea").val());
                                    self.allocateEvent();
                                });
                                //保存镜像
                                $(".saveImg").off("click").click(function () {
                                    if ($(".virMBox").length == 1) {
                                        $("body").append(saveImage());
                                        $(".radioc").off("click").click(function () {
                                            $(".radioc").removeClass("radioCheck2");
                                            $(this).addClass("radioCheck2");
                                            if($(this).attr("data-value") == 2){
                                                $(".inBox ").show();
                                            }else{
                                                $(".inBox ").hide();
                                            }
                                        });
                                        $(".imageClose").off("click").click(function () {
                                            $(".saveImgBg").remove();
                                            $(".saveImageBox").remove();
                                        });
                                        $(".saveImgTrue").off("click").click(function () {
                                            if ($("#imgName").val() == ""&&$(".radioCheck2").attr("data-value") == 2) {
                                                Alert1.content = "请输入镜像名称";
                                                Alert1.init();
                                                Alert1.show();
                                            } else {
                                                if ($(".virMBox").length == 1) {
                                                    if ($(".radioCheck2").attr("data-value") == 1) {
                                                        loading1.show();
                                                        var json = JSON.stringify({
                                                            "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                        });
                                                        $.ajax({
                                                            type: "post",
                                                            url: "image/cover",
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            data: json,
                                                            async: true,
                                                            success: function (msg) {
                                                                loading1.hide();
                                                                if (msg.code == 200) {
                                                                    loading1.show();
                                                                    var json = {"chapterIds": [result.paramData.chapterId]};
                                                                    json.courseId = 0;
                                                                    json.cluster = false;
                                                                    json.imageId = msg.data.imageId;
                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                    json.flavor = flavor;
                                                                    json = JSON.stringify(json);
                                                                    $.ajax({
                                                                        type: "post",
                                                                        url: "image/allocate/confirm",
                                                                        data: json,
                                                                        dataType: "JSON",
                                                                        contentType: 'application/json',
                                                                        async: true,
                                                                        success: function (msg) {
                                                                            loading1.hide();
                                                                            if (msg.code == 200) {
                                                                                Alert1.content = "保存镜像成功";
                                                                                $(".saveImgBg").remove();
                                                                                $(".saveImageBox").remove();
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                var url = $(".virMBox[data-value=1]").attr("src");
                                                                                $(".virMBox[data-value=1]").attr("src", url);
                                                                            } else {
                                                                                Alert1.content = msg.message;
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                return false;
                                                                            }

                                                                        },
                                                                        error: function () {
                                                                            loading1.hide();
                                                                        }
                                                                    });
                                                                } else {
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    return false;
                                                                }
                                                            }
                                                        });
                                                    } else {
                                                        var json = JSON.stringify({
                                                            "imageName": $("#imgName").val(),
                                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                        });
                                                        loading1.show();
                                                        $.ajax({
                                                            type: "post",
                                                            url: "image/create",
                                                            dataType: 'json',
                                                            contentType: 'application/json',
                                                            data: json,
                                                            async: true,
                                                            success: function (msg) {
                                                                loading1.hide();
                                                                if (msg.code == 200) {
                                                                    loading1.show();
                                                                    var json = {"chapterIds": [result.paramData.chapterId]};
                                                                    json.courseId = 0;
                                                                    json.cluster = false;
                                                                    json.imageId = msg.data.imageId;
                                                                    json.flavor = flavor;
                                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                    json = JSON.stringify(json);
                                                                    $.ajax({
                                                                        type: "post",
                                                                        url: "image/allocate/confirm",
                                                                        data: json,
                                                                        dataType: "JSON",
                                                                        contentType: 'application/json',
                                                                        async: true,
                                                                        success: function (msg) {
                                                                            loading1.hide();
                                                                            if (msg.code == 200) {
                                                                                Alert1.content = "保存镜像成功";
                                                                                $(".saveImgBg").remove();
                                                                                $(".saveImageBox").remove();
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                var url = $(".virMBox[data-value=1]").attr("src");
                                                                                $(".virMBox[data-value=1]").attr("src", url);
                                                                            } else {
                                                                                Alert1.content = msg.message;
                                                                                Alert1.init();
                                                                                Alert1.show();
                                                                                return false;
                                                                            }

                                                                        },
                                                                        error: function () {
                                                                            loading1.hide();
                                                                        }
                                                                    });
                                                                } else {
                                                                    Alert1.content = msg.message;
                                                                    Alert1.init();
                                                                    Alert1.show();
                                                                    return false;
                                                                }
                                                            }
                                                        });
                                                    }
                                                }
                                            }
                                        });
                                    } else {
                                        loading1.show();
                                        var json = JSON.stringify({
                                            "imageId": Number($(".virMBox[data-value=1]").attr("data-imageid")),
                                            "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                        });
                                        $.ajax({
                                            type: "post",
                                            url: "image/cover",
                                            dataType: 'json',
                                            contentType: 'application/json',
                                            data: json,
                                            async: true,
                                            success: function (msg) {
                                                loading1.hide();
                                                if (msg.code == 200) {
                                                    var json = {"chapterIds": [result.paramData.chapterId]};
                                                    json.courseId = 0;
                                                    json.cluster = false;
                                                    json.imageId = msg.data.imageId;
                                                    json.flavor = flavor;
                                                    $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                    json = JSON.stringify(json);
                                                    $(".saveImgBg").remove();
                                                    $(".saveImageBox").remove();
                                                    var json = JSON.stringify({
                                                        "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                        "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                        "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                    });
                                                    $.ajax({
                                                        type: "post",
                                                        url: "cluster/create",
                                                        dataType: 'json',
                                                        contentType: 'application/json',
                                                        data: json,
                                                        async: true,
                                                        success: function (msg) {
                                                            loading1.hide();
                                                            if (msg.code == 200) {
                                                                var json = {"chapterIds": [result.paramData.chapterId]};
                                                                json.courseId = 0;
                                                                json.cluster = true;
                                                                json.clusterId = msg.data.clusterId;
                                                                json.flavor = flavor;
                                                                json = JSON.stringify(json);
                                                                loading1.show();
                                                                $.ajax({
                                                                    type: "post",
                                                                    url: "image/allocate/confirm",
                                                                    data: json,
                                                                    dataType: "JSON",
                                                                    contentType: 'application/json',
                                                                    async: true,
                                                                    success: function (msg) {
                                                                        loading1.hide();
                                                                        if (msg.code == 200) {
                                                                            Alert2.content = "保存集群成功";
                                                                            Alert2.init();
                                                                            Alert2.show();
                                                                            $(".saveImgBg").remove();
                                                                            $(".saveImageBox").remove();
                                                                            var url = $(".virMBox[data-value=1]").attr("src");
                                                                            $(".virMBox[data-value=1]").attr("src", url);
                                                                        } else {
                                                                            Alert1.content = msg.message;
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                            return false;
                                                                        }

                                                                    },
                                                                    error: function () {
                                                                        loading1.hide();
                                                                    }
                                                                });
                                                            } else {
                                                                Alert1.content = msg.message;
                                                                Alert1.init();
                                                                Alert1.show();
                                                                return false;
                                                            }
                                                        }
                                                    });

                                                } else {
                                                    confirm1.content = "不允许覆盖公有的镜像，确定创建新的镜像吗？";
                                                    confirm1.success = function () {
                                                        $("body").append(saveImage());
                                                        $(".radioc").eq(0).removeClass("radioCheck2");
                                                        $(".radioc").eq(1).addClass("radioCheck2");
                                                        $(".inBox").show();
                                                        $(".hideBox").hide();
                                                        $(".radioc").off("click").click(function () {
                                                            $(".radioc").removeClass("radioCheck2");
                                                            $(this).addClass("radioCheck2");
                                                            if($(this).attr("data-value") == 2){
                                                                $(".inBox ").show();
                                                            }else{
                                                                $(".inBox ").hide();
                                                            }
                                                        });
                                                        $(".imageClose").off("click").click(function () {
                                                            $(".saveImgBg").remove();
                                                            $(".saveImageBox").remove();
                                                        });
                                                        $(".saveImgTrue").off("click").click(function () {
                                                            if ($("#imgName").val() == ""&&$(".radioCheck2").attr("data-value") == 2) {
                                                                Alert1.content = "请输入镜像名称";
                                                                Alert1.init();
                                                                Alert1.show();
                                                            } else {
                                                                var json = JSON.stringify({
                                                                    "imageName": $("#imgName").val(),
                                                                    "containerId": Number($(".virMBox[data-value=1]").attr("data-containerid"))
                                                                });
                                                                loading1.show();
                                                                $.ajax({
                                                                    type: "post",
                                                                    url: "image/create",
                                                                    dataType: 'json',
                                                                    contentType: 'application/json',
                                                                    data: json,
                                                                    async: true,
                                                                    success: function (msg) {
                                                                        loading1.hide();
                                                                        if (msg.code == 200) {
                                                                            loading1.hide();
                                                                            var json = {"chapterIds": [result.paramData.chapterId]};
                                                                            json.courseId = 0;
                                                                            json.cluster = false;
                                                                            json.imageId = msg.data.imageId;
                                                                            json.flavor = flavor;
                                                                            $(".virMBox[data-value=1]").attr("data-imageid", msg.data.imageId);
                                                                            json = JSON.stringify(json);
                                                                            var json = JSON.stringify({
                                                                                "masterImageId": Number($(".virMBox").eq(0).attr("data-imageid")),
                                                                                "firstSlaveImageId": Number($(".virMBox").eq(1).attr("data-imageid")),
                                                                                "secondSlaveImageId": Number($(".virMBox").eq(2).attr("data-imageid"))
                                                                            });
                                                                            $.ajax({
                                                                                type: "post",
                                                                                url: "cluster/create",
                                                                                dataType: 'json',
                                                                                contentType: 'application/json',
                                                                                data: json,
                                                                                async: true,
                                                                                success: function (msg) {
                                                                                    loading1.hide();
                                                                                    if (msg.code == 200) {
                                                                                        var json = {"chapterIds": [result.paramData.chapterId]};
                                                                                        json.courseId = 0;
                                                                                        json.cluster = true;
                                                                                        json.clusterId = msg.data.clusterId;
                                                                                        json.flavor = flavor;
                                                                                        json = JSON.stringify(json);
                                                                                        loading1.show();
                                                                                        $.ajax({
                                                                                            type: "post",
                                                                                            url: "image/allocate/confirm",
                                                                                            data: json,
                                                                                            dataType: "JSON",
                                                                                            contentType: 'application/json',
                                                                                            async: true,
                                                                                            success: function (msg) {
                                                                                                loading1.hide();
                                                                                                if (msg.code == 200) {
                                                                                                    Alert2.content = "保存集群成功";
                                                                                                    Alert2.init();
                                                                                                    Alert2.show();
                                                                                                    $(".saveImgBg").remove();
                                                                                                    $(".saveImageBox").remove();
                                                                                                    var url = $(".virMBox[data-value=1]").attr("src");
                                                                                                    $(".virMBox[data-value=1]").attr("src", url);
                                                                                                } else {
                                                                                                    Alert1.content = msg.message;
                                                                                                    Alert1.init();
                                                                                                    Alert1.show();
                                                                                                    return false;
                                                                                                }

                                                                                            },
                                                                                            error: function () {
                                                                                                loading1.hide();
                                                                                            }
                                                                                        });
                                                                                    } else {
                                                                                        Alert1.content = msg.message;
                                                                                        Alert1.init();
                                                                                        Alert1.show();
                                                                                        return false;
                                                                                    }
                                                                                }
                                                                            });
                                                                            $(".saveImgBg").remove();
                                                                            $(".saveImageBox").remove();
                                                                        } else {
                                                                            Alert1.content = msg.message;
                                                                            Alert1.init();
                                                                            Alert1.show();
                                                                            return false;
                                                                        }
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    };
                                                    confirm1.init();
                                                    confirm1.show();
                                                }
                                            }
                                        });
                                    }
                                });
                            }else{
                                Alert1.content = msg.message;
                                Alert1.init();
                                Alert1.show();
                                return false;
                            }
                        }
                    });
                }
            });
        },
        fileEvent:function () {
            $(".file").off("change").change(function() {
                var formData = new FormData($(this).parent()[0]);

                formData.append("chapterId", result.paramData.chapterId);
                if($(this).val() != ""){
                    count = 0;
                    var type = $(this).val().substring($(this).val().lastIndexOf(".")).toLowerCase(); // 取文件格式后缀名
                    var flag = true;
                    if($(this).attr("data-type") != undefined){
                        if(type != $(this).attr("data-type")) {
                            $(this).val("");
                            Alert1.content = "请上传正确格式文件，谢谢合作！";
                            Alert1.init();
                            Alert1.show();
                            flag = false;
                        }
                    }
                    if($(this).attr("data-size") != undefined){
                        if($(this)[0].files[0].size > $(this).attr("data-size")*1024*1024) {
                            $(this).val("");
                            Alert1.content = "上传文件最大为"+ $(this).attr("data-size") +"M，谢谢合作！";
                            Alert1.init();
                            Alert1.show();
                            flag = false;
                        }
                    }
                    var that = $(this);
                    if(that.attr("data-url") == 'addChapterHomework' || that.attr("data-url") == 'addChapterExpreexcel'){
                        formData.append("mark",1);
                    }
                    if(flag){
                        loading1.show();
                        $.ajax({
                            url: that.attr("data-url"),
                            type: 'post',
                            data: formData,
                            async: true,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success: function(msg) {
                                loading1.hide();
                                msg = JSON.parse(msg);
                                if(msg.result == "success") {
                                    Alert1.content = "上传成功";
                                    Alert1.init();
                                    Alert1.show();
                                    var str = "";
                                    if(that.attr("name") == "courseware"){
                                        str = "delCourseware";
                                    }else if(that.attr("name") == "homeworkexcel"){
                                        str = "delHomework";
                                    }else if(that.attr("name") == "video"){
                                        str = "delVideo";
                                    }else if(that.attr("name") == "expreexcel"){
                                        str = "delExprement";
                                    }else{
                                        str = "delPackageFile";
                                    }
                                    that.parent().siblings("h5").html("<span>"+ that.val().substring(that.val().lastIndexOf("\\")+1)+"</span><img src='pc/images/ico_uploadRemove.png' data-text='"+ str +"' class='delBtn'>");
                                    that.val("");
                                    if(msg.expreList!=undefined){
                                        var str = escape(labModel(msg.expreList[0]));
                                        var json = JSON.stringify({"homeOrExpreMark":2,"chapterId":msg.charpterId,"homewokHtmlStr":"","expreHtmlStr":str,"homworkPaperDetail":"","exprementPaperDetail":msg.expreList[0].exprelibrarySource});
                                        $.ajax({
                                            type: 'post',
                                            url: 'addHtmlChapter',
                                            async: true,
                                            data: {
                                                "jsonStr": json
                                            },
                                            success: function (msg) {
                                                msg = JSON.parse(msg);
                                                if (msg.result != "success") {
                                                    Alert1.content = msg.failMsg;
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });
                                    }
                                    if(msg.taskOptionList != undefined || msg.taskManyOptionList != undefined ||msg.taskBlankList != undefined ||msg.taskJudgeList != undefined ||msg.taskAnswerList != undefined ){
                                        var strings = "";
                                        var num = 0;
                                        count = 0;
                                        var str = "";
                                        var str1 = "";
                                        var str2 = "";
                                        var str3 = "";
                                        var str4 = "";
                                        if(msg.taskOptionList.length!=0){
                                            // num++;
                                            str = choseModel(num,msg.taskOptionList);
                                            num += msg.taskOptionList.length;
                                        }
                                        if(msg.taskManyOptionList.length!=0){

                                            str4 = muchModel(num,msg.taskManyOptionList);
                                            num +=msg.taskManyOptionList.length;
                                        }
                                        if(msg.taskJudgeList.length!=0){
                                            // num++;
                                            str1 = checkModel(num,msg.taskJudgeList);
                                            num +=msg.taskJudgeList.length;
                                        }
                                        if(msg.taskBlankList.length!=0){
                                            // num++;
                                            str2 = fillModel(num,msg.taskBlankList);
                                            num +=msg.taskBlankList.length;
                                        }
                                        if(msg.taskAnswerList.length!=0){
                                            // num++;
                                            str3 = shortModel(num,msg.taskAnswerList);
                                            num +=msg.taskBlankList.length;
                                        }
                                        strings = "<div class='homeShowBox'>"+str+str4+str1+str2+str3+"</div>";
                                        var json = JSON.stringify({"homeOrExpreMark":1,"chapterId":msg.charpterId,"homewokHtmlStr":escape(strings.replace(/\(\+\)/g,"(&emsp;&emsp;)")),"expreHtmlStr":"","homworkPaperDetail":JSON.stringify(msg),"exprementPaperDetail":"","cssStr":'@charset "utf-8";button:focus,input,input:focus,select,textarea:focus{outline:0}body,dd,dl,dt,form,h1,h2,h3,h4,h5,h6,input,li,ol,p,textarea,ul{margin:0;padding:0}select::-ms-expand{display:none;}select{border:1px solid #dcd9d9;appearance:none;-moz-appearance:none;-webkit-appearance:none;background:url(../../images/select.gif) right 10px center no-repeat #FFF}body,html{width:100%}label{font-size:16px!important;}.popup_content{font-size:16px!important;}body{font-size:16px;line-height:1.7;font-family:"Microsoft YaHei",simhei;color:#333;background-color:#ffffff;}input,select,textarea{color:#333;outline:none;}input{border:1px solid #dfdfdf;}input[type=checkbox]{-webkit-appearance:none;appearance:none;width:14px;vertical-align:middle;height:14px;margin:0;cursor:pointer;background:#fff;border:1px solid #a0a0a0;-webkit-border-radius:1px;-moz-border-radius:1px;border-radius:3px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;}input[type=checkbox]:active,input[type=radio]:active{border-color:#a0a0a0;background:#fff;}input[type=checkbox]:hover{border-color:#a0a0a0;-webkit-box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);-moz-box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);box-shadow:inset 0 2px 2px rgba(0,0,0,0.1);}input[type=checkbox]:checked,input[type=radio]:checked{background:#fff;}input[type=checkbox]:checked::after{content:url(../../images/ico_ok.png);display:block;position:absolute;top:-2px;left:2px;}input[type=checkbox]:focus{outline:none;border-color:#a0a0a0;}input[type=text]:focus{outline:none;}input:-webkit-autofill{-webkit-box-shadow:0 0 0px 1000px white inset;}ul,ol{list-style:none;}a{text-decoration:none;color:#333;font-size:16px}a:visited{color:#333;}a:hover,a:active,a:focus{color:#333;}em,i{font-style:normal}b,strong{font-weight:normal;}.fl{float:left}.fr{float:right}.clear{clear:both;height:0;overflow:hidden;}img{font-size:0;display:block;overflow:hidden;}table{table-layout:fixed;}td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}::-webkit-input-placeholder{color:#999999;}:-moz-placeholder{color:#999999;}::-moz-placeholder{color:#999999;}:-ms-input-placeholder{color:#999999;}.masking,.mb{position:fixed;width:100%;height:100%;z-index:0;background:rgba(0,0,0,0.7);top:0;left:0;display:none;}.choseOne{padding:0 15px;margin-bottom:10px;}.trueAnswer{margin-left:16px;color:#c80211;}.shortAnswer{width:50%;height:130px;resize:none;font-size:16px;padding:20px;display:none;}.answerInt{width:50px;height:20px;border:none;padding:0 5px;text-align:center;font-size:16px;min-width:50px;word-break:break-all;}.choseOne .shortAnswer{border:1px solid #cdcdcd;height:100px;width:500px;margin:20px 0;text-align:left;padding:10px;display:none;}.getScoreInt{height:20px;width:50px;text-align:center;}.getDisplay{color:#c80211;margin-left:46px;display:none;}.saveMar,.saveHome{display:none}#contentBox{background:#fff;}#contentBox>div{margin:0;}textarea{display:none!important;}',
                                        });
                                        $.ajax({
                                            type: 'post',
                                            url: 'addHtmlChapter',
                                            async: true,
                                            data: {
                                                "jsonStr": json
                                            },
                                            success: function (msg) {
                                                msg = JSON.parse(msg);
                                                if (msg.result != "success") {
                                                    Alert1.content = msg.failMsg;
                                                    Alert1.init();
                                                    Alert1.show();
                                                }
                                            }
                                        });

                                    }
                                    $(".delBtn").off("click").click(function () {
                                        var $that = $(this);
                                        var text = $(this).attr("data-text");
                                        var json = {"chapterId":result.paramData.chapterId};
                                        if(text == "delCourseware"){
                                            json.delCourseware = true;
                                        }else if(text == "delHomework"){
                                            json.delHomework = true;
                                        }else if(text == "delVideo"){
                                            json.delVideo = true;
                                        }else if(text == "delExprement"){
                                            json.delExprement = true;
                                        }else{
                                            json.delPackageFile = true;
                                        }
                                        json = JSON.stringify(json);
                                        confirm1.content = "确定要删除吗？";
                                        confirm1.success = function () {
                                            $.ajax({
                                                type: 'post',
                                                url: 'delChapterFile',
                                                async: true,
                                                data: {
                                                    "jsonStr": json
                                                },
                                                success: function (msg) {
                                                    msg = JSON.parse(msg);
                                                    if (msg.result == "success") {
                                                        that.val("");
                                                        $that.parent().html("");
                                                        count = 0;
                                                    }else{
                                                        Alert1.content = msg.failMsg;
                                                        Alert1.init();
                                                        Alert1.show();
                                                    }
                                                }
                                            });
                                        };
                                        confirm1.init();
                                        confirm1.show();
                                    });
                                } else {
                                    Alert1.content = msg.failMsg;
                                    that.val("");
                                    Alert1.init();
                                    Alert1.show();
                                }
                            }
                        });
                    }
                }


            });
        },
        testEditor:function(id){
            testEditor = editormd(id, {
                width     : '98%',
                height    : 535,
                toc       : true,
                todoList  : true,
                path      : 'pc/js/extends/lib/',
                watch:false,
                emoji: true,
                tex:true,
                saveHTMLToTextarea : true,
                imageUpload : true,
                imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                imageUploadURL : "editormdPic/",
                flowChart: true,
                sequenceDiagram: true,
                dialogLockScreen : false,
                dialogShowMask : true,
                dialogDraggable : false,
                dialogMaskOpacity : 0.4,
                dialogMaskBgColor : "#000",
                toolbarIcons : function() {
                    return ["undo","redo","|","bold","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","|","list-ul","list-ol","hr","|","link","image","code","preformatted-text","code-block","table","|","watch","preview","fullscreen","clear"]
                }
            })
        },
        showContent:function (mark) {
            var self = this;
            if(mark == 1){
                $(".navBox>li:eq(3)").addClass("checkNav");
                $(".section>div:eq(3)").show();
                $(".navBox>li:eq(3),.navBox>li:eq(4),.navBox>li:eq(5),.navBox>li:eq(6)").show();
                $(".navBox>li:eq(0),.navBox>li:eq(1),.navBox>li:eq(2)").remove();
                $(".section>div:eq(0),.section>div:eq(1),.section>div:eq(2)").remove();

            }else if(mark == 2){
                $(".navBox>li:eq(0),.navBox>li:eq(1),.navBox>li:eq(2),.navBox>li:eq(6)").show();
                $(".navBox>li:eq(3),.navBox>li:eq(4),.navBox>li:eq(5)").remove();
                $(".navBox>li:eq(0)").addClass("checkNav");
                $(".section>div:eq(0)").show();
                $(".section>div:eq(3),.section>div:eq(4),.section>div:eq(5)").remove();
            }else{
                $(".section>div:eq(0)").show();
                $(".navBox>li:eq(0)").addClass("checkNav");
            }
            var i=0,j=0;
            $(".navBox>li").off("click").click(function () {
                $(".navBox>li").removeClass("checkNav");
                $(this).addClass("checkNav");
                $(".section>div").hide();
                $(".section>div").eq($(this).index()).show();

                if($(this).text() == "实验手册"){
                    // if(i==0){
                    //     self.testEditor("LabEditormd");
                    // }
                    // i++;
                    var val = $("#LabEditormd textarea").val();
                    self.testEditor("LabEditormd");
                    $("#LabEditormd textarea").val(val);
                    $("#LabEditormd .markdown-body").html('');
                }
                if($(this).text() == "备课材料"){
                    var val = $("#MarEditormd textarea").val();
                    self.testEditor("MarEditormd");
                    $("#MarEditormd textarea").val(val);
                    $("#MarEditormd .markdown-body").html('');
                }
            });
            self.fileEvent();
            // 备课材料保存
            $(".saveMar").off("click").click(function(){
                    var json = JSON.stringify({"htmlStr":$("#MarEditormd .editormd-preview").html(),"chapterId":result.paramData.chapterId,"testNameHtml":'',"courseMaterialNameHtml":escape($("#MarEditormd textarea").val()),"mark":1});
                if($("#MarEditormd textarea").val()!=''&& $("#MarEditormd .markdown-body").html() == ''){
                    Alert1.content = "请点击预览查看编写效果";
                    Alert1.init();
                    Alert1.show();
                }else{
                    loading1.show();
                    $.ajax({
                        type: 'post',
                        url: 'addChapterMaterialOrTest',
                        async: true,
                        data: {
                            "jsonStr": json
                        },
                        success: function (msg) {
                            loading1.hide();
                            msg = JSON.parse(msg);
                            if (msg.result == "success") {
                                Alert1.content = "保存成功";
                                Alert1.init();
                                Alert1.show();
                            }else{
                                if(msg.failMsg!=undefined){
                                    Alert1.content = msg.failMsg;
                                }else{
                                    Alert1.content = "保存失败";
                                }
                                Alert1.init();
                                Alert1.show();
                            }
                        }
                    });
                }

            });
            // 实验手册保存
            $(".saveLab").off("click").click(function(){
                var json = JSON.stringify({"htmlStr":$("#LabEditormd .editormd-preview").html(),"chapterId":result.paramData.chapterId,"testNameHtml":escape($("#LabEditormd textarea").val()),"courseMaterialNameHtml":'',"mark":2});
                if($("#LabEditormd textarea").val()!=''&& $("#LabEditormd .markdown-body").html() == ''){
                    Alert1.content = "请点击预览查看编写效果";
                    Alert1.init();
                    Alert1.show();
                }else{
                    loading1.show();
                    $.ajax({
                        type: 'post',
                        url: 'addChapterMaterialOrTest',
                        async: true,
                        data: {
                            "jsonStr": json
                        },
                        success: function (msg) {
                            loading1.hide();
                            msg = JSON.parse(msg);
                            if (msg.result == "success") {
                                Alert1.content = "保存成功";
                                Alert1.init();
                                Alert1.show();
                            }else{
                                if(msg.failMsg!=undefined){
                                    Alert1.content = msg.failMsg;
                                }else{
                                    Alert1.content = "保存失败";
                                }
                                Alert1.init();
                                Alert1.show();
                            }
                        }
                    });
                }

            });
            // 实验报告保存
            $(".saveReport").off("click").click(function(){
               loading1.show();
                var str = escape($(".edit").html());
                var json = JSON.stringify({"homeOrExpreMark":2,"chapterId":result.paramData.chapterId,"homewokHtmlStr":"","expreHtmlStr":str,"homworkPaperDetail":"","exprementPaperDetail":200});
                $.ajax({
                    type: 'post',
                    url: 'addHtmlChapter',
                    async: true,
                    data: {
                        "jsonStr": json
                    },
                    success: function (msg) {
                        loading1.hide();
                        msg = JSON.parse(msg);
                        if (msg.result != "success") {
                            if(msg.failMsg!=undefined){
                                Alert1.content = msg.failMsg;
                            }else{
                                Alert1.content = "保存失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }else{
                            Alert1.content = "保存成功";
                            Alert1.init();
                            Alert1.show();
                        }
                    }
                });
            });
        },
        getDataEvent:function () {
            var self = this;
            var json = JSON.stringify({"chapterId":result.paramData.chapterId});
            $.ajax({
                type:'post',
                url:'skipSaveChapter',
                async:true,
                data:{
                    "jsonStr":json
                },
                success:function (msg) {
                    msg = JSON.parse(msg);
                    if(msg.result == "success"){
                        $("#departNames").html(msg.chapterMsg.chapterName);
                        var addTestMark = msg.chapterMsg.addTestMark;
                        if(addTestMark == 1){
                            addTestMark = "实验课";
                            self.showContent(1);
                        }else if(addTestMark == 2){
                            addTestMark = "理论课";
                            self.showContent(2);
                        }else{
                            addTestMark = "理论及实验课";
                            self.showContent(3);
                        }
                        $("#chapterType").val(addTestMark);
                        $(".enterLab").off("click").click(function () {
                            self.allocateEvent();
                        });
                    }else{
                        if(msg.failMsg!=undefined){
                            Alert1.content = msg.failMsg;
                        }else{
                            Alert1.content = "保存失败";
                        }
                        Alert1.init();
                        Alert1.show();
                    }
                }
            })
        }
    };
    chapterAdd.init();
    //桌面共享
    function startWebSocket(containerId) {
        var path = "";
        $.ajax({
            type:"get",
            url: "common/project",
            async: true,
            success: function(msg) {
                if(msg.code == 200){
                    path = msg.data;
                    // var path = window.location.host+"/";
                    var wsuri = "ws://" + path + "webSocket/image/" + containerId ;
                    if('WebSocket' in window) {
                        ws = new WebSocket(wsuri);
                    } else if('MozWebSocket' in window) {
                        ws = new MozWebSocket(wsuri);
                    } else {
                        Alert1.content = "当前浏览器不支持websocket，不能进行桌面共享";
                        Alert1.init();
                        Alert1.show();
                    }
                    var myDate = new Date();
                    ws.onopen = function() {

                        console.log(myDate.getDate() + ":" + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() + ":" + myDate.getMilliseconds() + "--onopen");
                    };
                    ws.onmessage = function(evt) {


                    };

                    ws.onclose = function(evt) {
                        console.log(myDate.getDate() + ":" + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() + ":" + myDate.getMilliseconds() + "--onclose");
                    };
                    ws.onerror = function() {
                        console.log(myDate.getDate() + ":" + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds() + ":" + myDate.getMilliseconds() + "--onerror");
                    };
                }
            }
        });

    }
});